/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Model.Attribute;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 * This class is used to display the ontology tree
 * @author Toinamph
 */
public class MyTreeRenderer extends DefaultTreeCellRenderer {
        Icon conceptIcon;
        Icon attributeIcon;
 
        public MyTreeRenderer(Icon conceptIcon, Icon attributeIcon) {
            this.conceptIcon = conceptIcon;
            this.attributeIcon = attributeIcon;
        }
 
    @Override
        public Component getTreeCellRendererComponent(
                            JTree tree,
                            Object value,
                            boolean sel,
                            boolean expanded,
                            boolean leaf,
                            int row,
                            boolean hasFocus) {
 
            super.getTreeCellRendererComponent(
                            tree, value, sel,
                            expanded, leaf, row,
                            hasFocus);
            if (leaf && isAttribute(value)) {
                setIcon(attributeIcon);
                setToolTipText("This is an attribute");
            } else {
                setIcon(conceptIcon);
                setToolTipText("This is a concept"); //no tool tip
            }
 
            return this;
        }
 
        protected boolean isAttribute(Object value) {
            /*DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
            String nodeName = node.getUserObject().toString();
            if (Character.isLowerCase(nodeName.charAt(0)) ) { // attributes start with a lowercase
                return true;
            } 
 
            return false;*/
            Attribute att = new Attribute();
            if ( att.getClass().isInstance( ((DefaultMutableTreeNode)value).getUserObject() ) ) {
                return true;
            }
            return false;
        }
    }
